package net.yuxianghe.chromepool;

import net.yuxianghe.chromepool.util.Util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

/**
 * WebService
 * Created by hxy on 2017/5/25.
 */
public class WebService {

    private static Log log = LogFactory.getLog(WebService.class);


    private WebDriver webDriver = null;

    public WebService setWebDriver(WebDriver webDriver) {
        this.webDriver = webDriver;
        return this;
    }

    public String getHtml(String url, int waitSecondsTime) {
        if (webDriver == null) {
            log.error("webDriver is null,please check WebService setWebDriver.");

            return null;
        }
        webDriver.navigate().to(url);
        try {
            Thread.sleep(waitSecondsTime);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        WebElement webElement = Util.webDriverWaitWebElement(webDriver, By.xpath("/html"), waitSecondsTime);
        if (webElement != null) {
            return webElement.getAttribute("outerHTML");
        } else {
            return null;
        }

    }


}
